﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;

namespace WebReport
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            Chart1.Titles.Add("Performance Chart(Unit:ms)");
            Chart1.Legends.Add(new Legend());
            //Chart1.ChartAreas.Add(new ChartArea(chartArea2));

            
            
        }
        private void Report()
        {
            using (DefaultDBEntity db = new DefaultDBEntity())
            {
                var query = from p in db.Request
                            group p by p.RequestTimeFormat into g
                            select new
                            {
                                RequestTime = g.Key,
                                Localtion = g.Max(t => t.Location),
                                ClientTime = g.Average(t => t.ClientTime).Value,
                                ServerTime = g.Average(t => t.ServerTime).Value,
                                NetworkTime = g.Average(t => t.NetworkTime).Value
                            };
                var data = query.ToList();
                Series s = new Series("ShangHai");
                foreach (var item in data)
                {
                    DataPoint dp = new DataPoint();
                    dp.AxisLabel = item.RequestTime.Value.ToString("yyyy/MM/dd HH:mm");
                    dp.YValues[0] = item.ClientTime + item.NetworkTime + item.ServerTime;
                    s.Points.Add(dp);

                }
                s.ChartType = SeriesChartType.Spline;
                //s.ChartArea = chartArea1;
                s.IsVisibleInLegend = true;
                Chart1.Series.Add(s);

                Series nj = new Series("NanJing");
                foreach (var item in data)
                {
                    DataPoint dp = new DataPoint();
                    dp.AxisLabel = item.RequestTime.Value.ToString("yyyy/MM/dd HH:mm");
                    dp.YValues[0] = item.NetworkTime + item.ServerTime;
                    nj.Points.Add(dp);

                }
                nj.ChartType = SeriesChartType.Spline;
                //nj.ChartArea = chartArea1;
                nj.IsVisibleInLegend = true;
                Chart1.Series.Add(nj);

            }
        }

        //public void Char2()
        //{
        //    Series s2 = Chart2.Series[0];
        //    //s2.ChartArea = chartArea2;
        //    s2.ChartType = SeriesChartType.StackedColumn;

        //    Random    random = new Random();
        //    for (int pointIndex = 0; pointIndex < 10; pointIndex++)
        //    {
        //        s2.Points.AddY(random.Next(45, 95));
        //    }
        //    //DataPoint d2 = new DataPoint();
        //    //d2.AxisLabel = "test1";
        //    //d2.YValues = new double[] { 10.0, 2, 5 };
        //    //s2.Points.Add(d2);

        //    // Set chart type
        //    Chart2.Series["Series1"].ChartType = SeriesChartType.StackedArea100;

        //    // Show point labels
        //    Chart2.Series["Series1"].IsValueShownAsLabel = true;

        //    // Disable X axis margin
        //    Chart2.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;

        //    // Enable 3D
        //    Chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;

        //    //// Set the first two series to be grouped into Group1
        //    //Chart2.Series["LightBlue"]["StackedGroupName"] = "Group1";
        //    //Chart2.Series["Gold"]["StackedGroupName"] = "Group1";

        //    //// Set the last two series to be grouped into Group2
        //    //Chart2.Series["Red"]["StackedGroupName"] = "Group2";
        //    //Chart2.Series["DarkBlue"]["StackedGroupName"] = "Group2";

        //}
    }

}
